package com.woniuxy.springbootpro.interceptor;

import com.woniuxy.springbootpro.utile.CookieUtil;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Order(1)
public class FirstInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.out.println("拦截器执行" + request.getRequestURI());

        Cookie token = CookieUtil.getCookie("token", request.getCookies());
        System.out.println("token" + token);

        if(token == null){
            response.sendRedirect("login.html");
        }

        return true;
    }
}
